package org.clockworkmages.games.anno1186.situations.sexsettings.options;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.GameStateService;
import org.clockworkmages.games.anno1186.model.Fetish;
import org.clockworkmages.games.anno1186.model.option.Option;

public class EnableDisableSexSettingOption
		extends Option {

	private boolean isEnabled;
	private GameStateService gameStateService;
	private Fetish fetish;

	public EnableDisableSexSettingOption(Fetish fetish, boolean isEnabled) {
		this.isEnabled = isEnabled;
		this.fetish = fetish;
		this.setLabel(fetish.getName()
				+ " ("
				+ (isEnabled ? "Enabled, select to disable"
						: "Disabled, select to enable") + ")");
		this.setTooltip(fetish.getDescription());
		this.setTextAfter("'" + fetish.getName() + "' "
				+ (isEnabled ? "disabled" : "enabled"));
		gameStateService = GameBeansContext.getBean(GameStateService.class);
	}

	public void select() {
		if (isEnabled) {
			// disable:
			gameStateService.getGameState().getFetishesEnabled()
					.remove(fetish.getId());

		} else {
			// enable
			gameStateService.getGameState().getFetishesEnabled()
					.add(fetish.getId());
		}
		super.select();
	}
}
